import request from '@/utils/request-siddhi'
const baseSiddhi = '';
export function edgeValidator() {
  return request({
    method: 'post',
    url: '/editor/validator',
    headers: {
      "Content-Type": "application/json",
    }
  })
}
export function edgeListSiddhiApps(params) {
  return request({
    method: 'get',
    // /editor/workspace/listFiles/workspace?path=d29ya3NwYWNl&id=%23
    url: '/editor/workspace/listFiles/workspace',
    headers: {
      "Content-Type": "application/json",
    },
    params: params
  })
}
// 模拟的下拉框(全部的siddhi程序)
export function listSiddhiApps(params) {
  return request({
    method: 'get',
    url: '/editor/artifact/listSiddhiApps',
    headers: {
      "Content-Type": "application/json",
    },
    params: params
  })
}
// 模拟=根据siddhi名称,获取流
export function listStreams(params) {
  return request({
    method: 'get',
    url: '/editor/artifact/listStreams/' + params,
    headers: {
      "Content-Type": "application/json",
    },
  })
}
// 模拟=根据流和siddhi名称获取流的属性
export function listAttributes(params) {
  const { siddhiAppName, streamName } = params
  return request({
    method: 'get',
    url: '/editor/artifact/listAttributes/' + siddhiAppName + "/" + streamName,
    headers: {
      "Content-Type": "application/json",
    },
  })
}
export function edgeWrite(params) {
  return request({
    method: 'post',
    url: '/editor/workspace/write',
    headers: {
      'Content-Type': 'text/plain'
    },
    data: params
  })
}

export function edgeGetCode(params) {
  return request({
    method: 'post',
    url: '/editor/code-view',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: params
  })
}
export function deploy(params) {
  // baseSiddhi 这个删除 就会走代理 
  return request({
    method: 'post',
    url: '/editor/workspace/deploy',
    headers: {
      'Content-Type': 'application/json; charset=utf-8'
    },
    data: params
  })
}
export function edgeDesignView(params) {
  return request({
    method: 'post',
    url: baseSiddhi + '/editor/design-view',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: params
  })
}
export function edgeReadFile(params) {
  return request({
    method: 'post',
    url: '/editor/workspace/read',
    headers: {
      'Content-Type': 'text/plain'
    },
    data: params
  })
}

//var param = 'configName=eHgxLnNpZGRoaQ==';
export function edgeExistFile(param) {
  return request({
    method: 'post',
    url: '/editor/workspace/exists/workspace',
    headers: {
      'Content-Type': 'text/plain'
    },
    data: param
  })
}

export async function edgeReadPathSeparator() {
  return await request({
    method: 'get',
    url: '/editor/workspace/config',
    headers: {
      "Content-Type": "application/json",
    }
  })
}
export async function deleteSiddi(data) {
  return await request({
    method: 'DELETE',
    url: '/editor/workspace/delete',
    params: data,
    headers: {
      "Content-Type": "text/plain; charset=utf-8",
    }
  })
}
//var param ={"siddhiAppName":"tttt1","variables":{}}
export function edgeRunApp(param) {
  return request({
    method: 'post',
    url: baseSiddhi + '/editor/start',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: param
  })
}

export async function edgeStopApp(appName) {
  return await request({
    method: 'get',
    url: '/editor/' + appName + '/stop',
    headers: {}
  })
}
export function single(param) {
  return request({
    method: 'post',
    url: baseSiddhi + '/simulation/single',
    headers: {
      'Content-Type': 'text/plain'
    },
    data: param
  })
}
// 多例模拟列表获取
export function getFeed(data) {
  return request({
    method: 'get',
    url: '/simulation/feed',
    headers: {
      'Content-Type': 'application/json'
    },
  })
}
// 多例模拟列表获取
export function setFeed(data) {
  return request({
    method: 'post',
    url: '/simulation/feed',
    headers: {
      'Content-Type': 'text/plain'
    },
    data
  })
}
// 多例模拟列表获取
export function editFeed(data) {
  return request({
    method: 'put',
    url: '/simulation/feed/' + data.properties.simulationName,
    headers: {
      'Content-Type': 'text/plain'
    },
    data
  })
}
// 定时任务
export function feedStatus(data) {
  return request({
    method: 'get',
    url: '/simulation/feed/' + data + '/status',
    headers: {
      'Content-Type': 'text/plain'
    },
    data
  })
}
// 启动 
export function playFeed(data) {
  return request({
    method: 'post',
    url: '/simulation/feed/' + data.simulationName + '/?action=' + data.action,
    headers: {
      'Content-Type': 'application/json; charset=utf-8'
    },
    data
  })
}
// 多例模拟列表获取
export function delFeed(name) {
  return request({
    method: 'DELETE',
    url: '/simulation/feed/' + name,
    headers: {
      'Content-Type': 'application/json'
    },
  })
}
export function connectToDatabase(data) {
  return request({
    method: 'post',
    url: '/simulation/connectToDatabase',
    data,
    headers: {
      'Content-Type': 'application/json; charset=UTF-8'
    },
  })
}
export function retrieveTableNames(data) {
  return request({
    method: 'post',
    url: '/simulation/connectToDatabase/retrieveTableNames',
    data,
    headers: {
      'Content-Type': 'application/json; charset=UTF-8'
    },
  })
}
export function retrieveColumnNames(data, name) {
  return request({
    method: 'post',
    url: '/simulation/connectToDatabase/' + name + '/retrieveColumnNames',
    data,
    headers: {
      'Content-Type': 'application/json; charset=UTF-8'
    },
  })
}
export function getFiles(data, name) {
  return request({
    method: 'get',
    url: '/simulation/files',
    data,
    headers: {
      'Content-Type': 'application/json; charset=UTF-8'
    },
  })
}